home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / bash-1.08 / psize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-01  |  1.6 KB  |  82 lines

  1. /*
  2.  * psize -- find pipe size
  3.  *
  4.  * Write output in 128-byte chunks until we get a sigpipe or write gets an
  5.  * EPIPE.  Then report how many bytes we wrote.  This should be the pipe
  6.  * size.
  7.  */
  8.  
  9. /* Copyright (C) 1987,1991 Free Software Foundation, Inc.
  10.  
  11.    This file is part of GNU Bash, the Bourne Again SHell.
  12.  
  13.    Bash is free software; you can redistribute it and/or modify it
  14.    under the terms of the GNU General Public License as published by
  15.    the Free Software Foundation; either version 1, or (at your option)
  16.    any later version.
  17.  
  18.    Bash is distributed in the hope that it will be useful, but WITHOUT
  19.    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  20.    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  21.    License for more details.
  22.  
  23.    You should have received a copy of the GNU General Public License
  24.    along with Bash; see the file COPYING.  If not, write to the Free
  25.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  26.  
  27. #include <stdio.h>
  28. #include <signal.h>
  29. #include <errno.h>
  30.  
  31. #include "general.h"
  32. extern int errno;
  33.  
  34. int nw;
  35.  
  36. #if defined (VOID_SIGHANDLER)
  37. #define sighandler void
  38. #else
  39. #define sighandler int
  40. #endif
  41.  
  42. sighandler
  43. sigpipe (sig)
  44.      int sig;
  45. {
  46.   fprintf (stderr, "%d\n", nw);
  47.   exit (0);
  48. }
  49.  
  50. #if !defined (NeXT)
  51. char *
  52. memset (s, c, n)
  53.      register char *s;
  54.      register int c, n;
  55. {
  56.   register char *p = s;
  57.  
  58.   while (--n >= 0)
  59.     *s++ = c;
  60.  
  61.   return (p);
  62. }
  63. #endif /* !NeXT */
  64.  
  65. main (argc, argv)
  66.      int argc;
  67.      char **argv;
  68. {
  69.   char buf[128];
  70.  
  71.   memset (buf, ' ', 128);
  72.   signal (SIGPIPE, sigpipe);
  73.  
  74.   nw = 0;
  75.   for (;;)
  76.     {
  77.       int n;
  78.       n = write (1, buf, 128);
  79.       nw += n;
  80.     }
  81. }
  82.